package com.naiterui.ehp.bs.doctor.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.naiterui.common.redis.RedisUtil;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.doctor.exception.ExceptionCodes;
import com.naiterui.ehp.bs.doctor.remote.IAdRemoter;
import com.naiterui.ehp.bs.doctor.service.IPatientRecordService;
import com.naiterui.ehp.bs.doctor.utils.PropertyValueConstants;

@Service
public class AdPatientRecordServiceImpl implements IPatientRecordService {

    private static final Logger LOGGER = LoggerFactory.getLogger(AdPatientRecordServiceImpl.class);

    @Autowired
    private IAdRemoter remoter;

    @Override
    public void remindPatientSendRecord(Long doctorId, Long patientId) throws BusinessException {
        String redisKey = PropertyValueConstants.RDS_REMIND_PT_RECORD + doctorId + "_" + patientId;
        String flag = RedisUtil.valueOps().getString(redisKey);
        if (flag != null) {
            LOGGER.info("5分种内已提醒过该患者");
            return;
        }
        try {
            this.remoter.remindPatinetSend(patientId, doctorId);
            RedisUtil.valueOps().set(redisKey, 1, 5 * 60);
        } catch (BusinessException e) {
            LOGGER.error("提醒患者发送病历,doctorId:{},patientId:{}", doctorId, patientId);
            throw new BusinessException(ExceptionCodes.HTTP_ERR);
        }
    }


}
